package defense_against_all;

import java.awt.Image;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;
import java.util.ArrayList;

import javax.swing.ImageIcon;

public class Tank {
    private int dx;
    int backinx, backx, leftT;
    int x,y;
    private Image image;
    ImageIcon ii = new ImageIcon("GameDevelopment/DefenseAgainstAll/src/defense_against_all/image/Tank.gif");
    ImageIcon ic = new ImageIcon("GameDevelopment/DefenseAgainstAll/src/defense_against_all/image/TankL.gif");
    ImageIcon ifire = new ImageIcon("GameDevelopment/DefenseAgainstAll/src/defense_against_all/image/TankFire.gif");
    int ammunation_bombs = 100;
    
    static ArrayList bombs;

    public Tank() {
        x = 40;
        y = 313;
        backx = 788;
        backinx = 0;
        leftT = 100;
        image = ii.getImage();
        bombs = new ArrayList();
    }


    public void move() {
    	if(dx != -1){
    		if(leftT+dx <=300)
    			leftT = leftT+dx;
    		else{
    			x += dx;
    			backx +=dx;
    			backinx +=dx;
    			}
    	}
    		else{
    			if(leftT+dx > 0){
    				leftT = leftT+dx;
    			}
    		}
    }
    public static ArrayList getBombs(){
    	return bombs;
    }
    public void attack(){
    	if(ammunation_bombs > 0){
    		ammunation_bombs--;
    		Fire fire = new Fire(leftT+ii.getIconWidth(),y+(ii.getIconHeight())/2);
    		bombs.add(fire);
    	}
    }
    public Rectangle getBounds(){
		return new Rectangle(leftT,y,100,49);
	}
    public int backX(){
    	return backx;
    }
    public int getX() {
        return x;
    }

    public Image getImage() {
        return image;
    }
    public int getDx(){
    	return dx;
    }
    public void keyPressed(KeyEvent e) {

        int key = e.getKeyCode();

        if (key == KeyEvent.VK_LEFT) {
            dx = -1;
            image = ic.getImage();
        }

        if (key == KeyEvent.VK_RIGHT) {
        	image = ii.getImage();
            dx = 1;
        }
        if (key == KeyEvent.VK_B) {
        	image = ifire.getImage();
        	attack();
        	
        }
    }

    public void keyReleased(KeyEvent e) {
        int key = e.getKeyCode();

        if (key == KeyEvent.VK_LEFT) {
            dx = 0;
            
        }

        if (key == KeyEvent.VK_RIGHT) {
            dx = 0;
        }
        if (key == KeyEvent.VK_B) {
        	image = ii.getImage();
        }
    }
}
